"""
Contains our utilitie to fill pykodio's database

/file pkSongHounder
/author Guillaume
/date november 25th, 2012
"""

import unittest
from os import listdir


class pkSongHound:
	"""
	Utilitie that retrieve songs from given directories
	and add them to the pykodio database
	"""

	AUDIO_FORMATS = [".mp3", ".ogg"]

	def __init__(self):
		pass


	def list_audio_files(self, directory):
		""" List all audio file in the given directory """

		files_list = listdir(directory)
		audio_files_list = []

		for file_name in files_list:
			if self._check_for_audio_extension(file_name):
				audio_files_list.append(file_name)

		return audio_files_list


	def _check_for_audio_extension(self, file_name):
		""" Check whether the file is an audio file compatible with pykodio """

		for extension in pkSongHound.AUDIO_FORMATS:
			if file_name.endswith(extension):
				return True
		return False


	def add_audio_files_to_database(self, audio_files_list = []):
		""" Add songs of the given list into the database """

		for song in audio_files_list:
			pass



class TestSongHound(unittest.TestCase):

	def test_list_audio_file(self):
		self.hound = pkSongHound()
		result_list = self.hound.list_audio_files("../testSongs")
		expected_list = ["test.mp3", "test.ogg", "test2.mp3"]

		as_expected = self._check_have_same_elements(result_list, expected_list)

		self.assertTrue(as_expected)


	def _check_have_same_elements(self, list1, list2):
		""" Check if both lists have the same elements """

		for file_name1 in list1:
			if not file_name1 in list2:
				return False
		return True


	def test_add_audio_files(self):
		pass



if __name__ == "__main__":
	unittest.main()
